/**
 * Data Structure and Function for Search Results 
 */

package Utilities;

import java.util.Vector;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class SearchResults {
	private Vector<String> SearchURLPath;
	private Vector<String> SearchTitle;
	private Vector<String> SearchText;
	
	public SearchResults() {
		SearchURLPath = new Vector<String>();
		SearchTitle = new Vector<String>();
		SearchText = new Vector<String>(); 
	}
		
	public void AddSearchResult(String Path, String Title, String Text) {
		SearchURLPath.add(Path.replace("\\", "/"));
		SearchTitle.add(Title);
		SearchText.add(Text);
	}
	
	public void ThrowJSONSearchResults() {
		JSONArray JSONSearchResults = new JSONArray();
		int length = SearchURLPath.size();
		
		//Put all data into JSON data structure
		try {		
			//Put search results
            for(int i=0;i<length;++i) {
            	JSONObject SearchResult = new JSONObject();
            	SearchResult.put("link", SearchURLPath.elementAt(i));
            	SearchResult.put("title", SearchTitle.elementAt(i));
            	SearchResult.put("transcript", SearchText.elementAt(i));
            	JSONSearchResults.put(SearchResult);
            }
            
        } catch (JSONException ex) {
            ex.printStackTrace();
        }
        
        //Throw JSON string output
        System.out.println(JSONSearchResults.toString());
        
	}
}
